package session

import (
	"OnlineRetailers/models"
	"OnlineRetailers/models/Admin"
	"encoding/json"
	"github.com/garyburd/redigo/redis"
)

func FindSession(session string) (ses *Admin.Session, err error) {

	conn := models.Pool.Get()

	defer func() {
		err = conn.Close()
		if err != nil {

		}
	}()

	sessionJson, err := redis.Bytes(conn.Do("Get", session))
	if err != nil {
		return
	}
	err = json.Unmarshal(sessionJson, &ses)
	if err != nil {
		return
	}
	err = UpdateSession(session)

	return
}
